﻿using System;
using System.Threading;

namespace CoreLib
{
    public class LogThread
    {
        private readonly ILogWriter writer;
        private int runningThreadCount = 0;

        public int RunningThreadCount { get { return runningThreadCount; } }

        public LogThread(ILogWriter writer)
        {
            this.writer = writer;
        }

        public void Enqueue(Log log)
        {
            Thread t = new Thread(() =>
            {
                runningThreadCount++;
                try
                {
                    lock (writer)
                    {
                        writer.Write(log);
                    }
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    runningThreadCount--;
                }
            });
            t.Start();
        }
    }
}
